$.fn.navFixed = function(){
	var $_this = $(this),
		$_this_prev_marginBottom = parseInt($_this.prev().css("margin-bottom").substring(0, $_this.prev().css("margin-bottom").length-2)),
		$_this_next_marginTop = parseInt($_this.next().css("margin-top").substring(0, $_this.next().css("margin-top").length-2)),
		_topPosition = $(document).scrollTop(),
		_navPosition = $_this.prev().outerHeight(true);
	
	_if();

	$(document).scroll( function() {
		_topPosition = $(document).scrollTop();
		_if();
	});

	$(window).resize(function(){ 
		_navPosition = $_this.prev().outerHeight(true);
		_if();
	}); 

	function _if(){
		if (_topPosition >= _navPosition){
			$_this.css("position", "fixed");
			$_this.next().css("margin-top", $_this_prev_marginBottom + $_this.outerHeight() + $_this_next_marginTop + "px");
		}else{
			$_this.css("position", "relative");
			$_this.next().css("margin-top", $_this_next_marginTop + "px");
		}
	}
}

// 使用方法
// <script src="navFixed.min.js"></script>
// <script>
//     $(function(){
//         $(selector).navFixed();
//     });					
// </script>
// 
(function($) {
    $.fn.jCorner = function(options) {
        return this.each(function() {
            var settings = $.extend({
                size: 40,
                id: undefined,
                link: undefined,
                background: '#fff' 
            }, options);

            var id = settings.id === undefined ? '' : ' id="' 
                    + settings.id + '"';
            var a_start = settings.link === undefined ? '' : '<a href="'
                    + settings.link + '" target="_blank">';
            var a_end = settings.link === undefined ? '' : '</a>';
            var element = '<div' + id + ' class="jCorner" style="width: '
                    + settings.size * 2 + 'px; height: ' + settings.size
                    + 'px; position: absolute; bottom: 0; right: 0;">' + a_start
                    + '<div class="jCorner_left" style="border-width: 0 0 '
                    + settings.size + 'px ' + settings.size 
                    + 'px; width: 0px; height: 0px; border-style: solid; '
                    + 'border-color: transparent transparent #999 transparent; '
                    + 'opacity: 0.6; float: left; z-index: 10;"></div>'
                    + '<div class="jCorner_square" style="border-width: 0 0 '
                    + settings.size + 'px ' + settings.size 
                    + 'px; border-color: transparent transparent ' 
                    + settings.background 
                    + ' transparent; width: 0px; height: 0px; '
                    + 'border-style: solid; float: left;"></div>'
                    + '<div class="jCorner_right" '
                    + 'style="border-width: ' + settings.size + 'px ' 
                    + settings.size + 'px 0 0; left: ' + settings.size 
                    + 'px; top: -' + settings.size + 'px; width: 0px; '
                    + 'height: 0px; border-style: solid; '
                    + 'border-color: #fff transparent transparent transparent; '
                    + 'position: relative; opacity: 0.6; float: left; '
                    + 'z-index: 10;"></div>' 
                    + a_end;

            return $(this).append(element).css('position', 'relative');
        });
    }
}(jQuery));

// 使用方法
// $('#paper').jCorner({
    // size: 25,
//     background: 'black'
// });

// $('#paper').jCorner({
//     background: '#ffcc00',
//     link: 'about.html',
//     id: 'about'
// });